package com.onetoall.yjt.wxapi;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.onetoall.yjt.Contants;
import com.onetoall.yjt.R;
import com.tencent.mm.opensdk.constants.ConstantsAPI;
import com.tencent.mm.opensdk.modelbase.BaseReq;
import com.tencent.mm.opensdk.modelbase.BaseResp;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
	
	private static final String TAG = "MicroMsg.SDKSample.WXPayEntryActivity";
	
    private IWXAPI api;
	private WebView mOkWebView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay_result);

		//http://beta.yqg.1toall.com.cn/mobile/index.php",@"orderid":[userD stringForKey:@"order_id"]:?m=user&c=order&a=detail&order_id=%@

        mOkWebView = (WebView) findViewById(R.id.mOKWebView);
    	api = WXAPIFactory.createWXAPI(this, Contants.APP_ID);
        api.handleIntent(getIntent(), this);
		//mOkWebView.loadUrl();
    }

	@Override
	protected void onNewIntent(Intent intent) {
		super.onNewIntent(intent);
		setIntent(intent);
        api.handleIntent(intent, this);
	}

	@Override
	public void onReq(BaseReq req) {
	}

	@Override
	public void onResp(BaseResp resp) {

		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {

			/*AlertDialog.Builder builder = new AlertDialog.Builder(this);
			builder.setTitle(R.string.app_tip);
			builder.setMessage(getString(R.string.pay_result_callback_msg, String.valueOf(resp.errCode)));
			builder.show();*/
			//http://beta.yqg.1toall.com.cn/mobile/index.php?m=user&c=order&a=detail&order_id=145

			String order_id = PrefsAccessor.getInstance(getBaseContext()).getString("order_id", "");
			String url = "http://beta.yqg.1toall.com.cn/mobile/index.php?m=user&c=order&a=detail&order_id="+order_id;

			WebSettings settings = mOkWebView.getSettings();
			settings.setJavaScriptEnabled(true);
			settings.setUseWideViewPort(true);
			settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
			settings.setLoadWithOverviewMode(true);
			mOkWebView.loadUrl(url);
			mOkWebView.setWebViewClient(new WebViewClient(){
				@Override
				public boolean shouldOverrideUrlLoading(WebView view, String url) {
					view.loadUrl(url);
					return true;
				}
			});

			switch (resp.errCode) {
				case 0:

					break;
				case -1:

					break;
				case -2:

					break;
			}
		}
	}
}